# 请参阅 https://aka.ms/customizecontainer 以了解如何自定义调试容器，以及 Visual Studio 如何使用此 Dockerfile 生成映像以更快地进行调试。

# 此阶段用于在快速模式(默认为调试配置)下从 VS 运行时
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
USER app
WORKDIR /app
EXPOSE 8080


# 此阶段用于生成服务项目
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["IM.Easy.Api/IM.Easy.Api.csproj", "IM.Easy.Api/"]
COPY ["Services/IM.Easy.AuthorizationServices/IM.Easy.AuthorizationServices.csproj", "IM.Easy.AuthorizationServices/"]
COPY ["IM.Easy.CoreServices/IM.Easy.CoreServices.csproj", "IM.Easy.CoreServices/"]
COPY ["IM.Easy.Core/IM.Easy.Core.csproj", "IM.Easy.Core/"]
COPY ["IM.Easy.Infrastructure/IM.Easy.Infrastructure.csproj", "IM.Easy.Infrastructure/"]
COPY ["IM.Easy.Entity/IM.Easy.Entity.csproj", "IM.Easy.Entity/"]
COPY ["Services/IM.Easy.GenServices/IM.Easy.GenServices.csproj", "IM.Easy.GenServices/"]
COPY ["Services/IM.Easy.LogServices/IM.Easy.LogServices.csproj", "IM.Easy.LogServices/"]
COPY ["Services/IM.Easy.SystemServices/IM.Easy.SystemServices.csproj", "IM.Easy.SystemServices/"]
COPY ["Plugins/AMapPlugin/AMapPlugin.csproj", "Plugins/AMapPlugin/"]

RUN dotnet nuget remove source nuget.org
RUN dotnet nuget add source https://repo.huaweicloud.com/repository/nuget/v3/index.json -n hw_nuget
RUN dotnet restore "./IM.Easy.Api/IM.Easy.Api.csproj"
COPY . .
WORKDIR "/src/IM.Easy.Api"
RUN dotnet build "./IM.Easy.Api.csproj" -c $BUILD_CONFIGURATION -o /app/build

# 此阶段用于发布要复制到最终阶段的服务项目
FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./IM.Easy.Api.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

# 此阶段在生产中使用，或在常规模式下从 VS 运行时使用(在不使用调试配置时为默认值)
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .


USER root
RUN echo "deb http://mirrors.163.com/debian bullseye main" >> /etc/apt/sources.list
RUN echo "deb http://mirrors.163.com/debian-security bullseye-security main" >> /etc/apt/sources.list
RUN echo "deb http://mirrors.163.com/debian bullseye-updates main" >> /etc/apt/sources.list

# 添加阿里云镜像源
#RUN echo "deb http://mirrors.aliyun.com/debian bullseye main" >> /etc/apt/sources.list
#RUN echo "deb http://mirrors.aliyun.com/debian-security bullseye-security main" >> /etc/apt/sources.list
#RUN echo "deb http://mirrors.aliyun.com/debian bullseye-updates main" >> /etc/apt/sources.list

#安装fontconfig
RUN apt-get clean
RUN apt-get update && apt-get upgrade -y && apt-get install -y fontconfig

ENTRYPOINT ["dotnet", "IM.Easy.Api.dll"]